/*   Copyright © 2009 Mark Gil Torres
 *
 *   This file is part of mtoolkit.
 *
 *   mtoolkit is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   mtoolkit is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with mtoolkit.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>
#include <string>
#include <stack>

#include "mt_grammar.hpp"
#include "variant.hpp"

using namespace mt;
using namespace std;

int main(int argc, char** argv) {
  stack<Variant> inStack;
  MGrammar g(inStack);
  string input, preInput="";
  cout<<"mt# ";
  while(getline(cin,input)) {
    input = preInput + input;
    if (input.empty() || input == "quit") break;
    parse_info<> info = parse(input.c_str(),g,space_p);

    if(info.full) {
        preInput = "";
        cout<<"mt# ";
//      cout << "\nParse successful\n";
    }
    else {
      if (*info.stop == '\0') {
        preInput = input;
//        cout << preInput << endl;
      }
      else {
        preInput = "";
        cout << "\nParsing failed at \"" << info.stop << "\"\n";
        cout<<"mt# ";
      }
    }
  }
  return 0;
}
